//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Base/Events/EventTransmitter.h"
#include "Base/Platform/VideoSettings.h"
#include "Platforms/Base/DeviceWrapper.h"
#include "Platforms/Base/HardwareCamera.h"


namespace Engine
{
namespace Platforms
{

	//
	// Base Platform
	//

	class IPlatform
	{
	// types
	public:
		typedef array< TPair< string, string > >										key_value_array_t;

		//typedef delegate< void (const key_value_array_t &) >							OnGetProductList_t;
		typedef delegate< void (ELicenseCheckResponse::type, const string &error) >		OnLicenseChecked_t;
		typedef delegate< void (/*EMessageResult*/int result) >							OnMessageResult_t;

		struct EMessageResult
		{
			enum type
			{
				POSITIVE = 1,
				NEGATIVE = -1
			};
		};


	// variables
	protected:
		DeviceWrap		_device;


	// interface
	public:
		virtual ~IPlatform () {}

		// Sensor //
		virtual bool EnableSensor (ESensor::type sensor) = 0;
		virtual bool DisableSensor (ESensor::type sensor) = 0;
		virtual bool IsSensorEnabled (ESensor::type sensor) = 0;
		virtual bool SetSensorUpdateRate (ESensor::type sensor, uint rate) = 0;
		virtual bool HasSensor (ESensor::type sensor) = 0;
		// TODO: get sensor info

		// Render //
		virtual bool InitRender (INOUT VideoSettings &vs) = 0;
		virtual void SwapBuffers () = 0;
		virtual bool IsRenderingAvailable () = 0;

		// Audio //
		virtual void EnableAudio (bool enabled) = 0;

		// Extensions //
		virtual Ptr< HardwareCamera > GetCamera () = 0;

		// Billing //
		//virtual bool IsBillingSupported () = 0;
		//virtual void GetProductList () = 0;

		// License //
		virtual void CheckLicense (const OnLicenseChecked_t &callback, uni_c_string publicKey) = 0;

		// Other //
		virtual void Terminate () = 0;
		
		virtual void Vibrate (const uni_array<const int64> &pattern) = 0;

		virtual void InitDevice (EDevice::type deviceType = EDevice::AUTO) = 0;
		virtual void SetDisplayOrientation (EDisplayOrientation::type orientation) = 0;

		//virtual void BackgroundMode (bool enabled) = 0;

		virtual void SendEmail (uni_c_string address, uni_c_string subject,
								uni_c_string text, uni_c_string attachment) = 0;
		
		virtual void OpenURL (uni_c_string url) = 0;

		virtual void ShowNotification (uni_c_string text, bool longTime = false) = 0;

		virtual void ShowMessage (const OnMessageResult_t &callback,
								  uni_c_string caption, uni_c_string text,
								  uni_c_string positive, uni_c_string negative) = 0;

		virtual EventSystemPtr		GetEventSystem () = 0;	// can be null
		virtual IParallelThreadPtr	GetThread () = 0;		// can be null

		virtual uni_c_string 		GetDirectoryPath (EDirectory::type type) = 0;



	// methods
	public:
		bool SetSensorState (ESensor::type sensor, bool enabled)
		{
			return enabled ? EnableSensor( sensor ) : DisableSensor( sensor );
		}

		Device const &		GetDevice ()	const	{ return _device; }
		Display const &		GetDisplay ()	const	{ return GetDevice().GetDisplay(); }
	};


}	// Platforms
}	// Engine